package com.huiyou.control;

import com.huiyou.base.AppBack;
import com.huiyou.model.AdminModel;
import com.huiyou.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class BaseController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/loginAdmin")
    @ResponseBody
    public AppBack hello(@RequestParam String username,
                         @RequestParam String password,
                         HttpServletRequest request) {
        Map condition=new HashMap();
        condition.put("username",username);
        condition.put("password",password);
        List<AdminModel> list = adminService.getList(condition);
        if(list.size()==0){
            return new AppBack(-1,"用户名或密码错误");
        }
        if(list.get(0).getStatus()!= 0){
            return new AppBack(-1,"账号被冻结");
        }
        request.getSession().setAttribute("admin",list.get(0));
        return new AppBack();
    }


}
